package com.jz.community.moduleothers.scan.ui;

import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.jz.community.basecomm.base.BaseMvpActivity;
import com.jz.community.basecomm.mvp.BaseMvpPresenter;
import com.jz.community.basecomm.routerUtils.RouterIntentConstant;
import com.jz.community.commview.commPagerAdapter.CommonViewPagerAdapter;
import com.jz.community.moduleothers.R;
import com.jz.community.moduleothers.R2;

import butterknife.BindView;

@Route(path = RouterIntentConstant.CARD_SCAN)
public class CardScanActivity extends BaseMvpActivity {
    @BindView(R2.id.card_viewpager)
    ViewPager card_viewpager;
    @BindView(R2.id.scan_back_left)
    ImageView scanBackLeft;
    @BindView(R2.id.home_qr_title)
    TextView homeQrTitle;
    @BindView(R2.id.home_qr_menu)
    ImageView homeQrMenu;
    @BindView(R2.id.scan_qr_toolbar)
    Toolbar scanQrToolbar;
    private QRHomeFragment qrHomeFragment;
    private String cardno;
    private String cardId;
    private int cardType;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setImmersionBar(scanQrToolbar);
    }

    @Override
    protected int getContentView() {
        return R.layout.module_others_card_scan_layout;
    }

    @Override
    protected BaseMvpPresenter createPresenter() {
        return null;
    }

    @Override
    protected void addListener() {
        super.addListener();
        scanBackLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        homeQrMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                qrHomeFragment.showMoneyDetailPop(v);
            }
        });
    }

    @Override
    protected void initDatas() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
        cardno = getIntent().getStringExtra("cardno");
        cardId = getIntent().getStringExtra("cardId");
        cardType = getIntent().getIntExtra("cardType", -1);
        initViewPager();
    }

    private void initViewPager() {
        CommonViewPagerAdapter viewPagerAdapter = new CommonViewPagerAdapter(getSupportFragmentManager());
        qrHomeFragment = QRHomeFragment.newInstance(cardno, cardType, cardId);
        viewPagerAdapter.addFragment(qrHomeFragment);
        card_viewpager.setAdapter(viewPagerAdapter);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
